package com.yanfan.point.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import com.yanfan.point.domain.IbmsDeviceType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.point.domain.IbmsDeviceGroup;
import com.yanfan.point.service.IIbmsDeviceGroupService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 设备分组Controller
 *
 * @author genluo
 * @date 2024-10-10
 */
@Api(tags = "设备分组")
@RestController
@RequestMapping("/point/deviceGroup")
public class IbmsDeviceGroupController extends BaseController {
    @Autowired
    private IIbmsDeviceGroupService ibmsDeviceGroupService;

    /**
     * 查询设备分组列表
     */
    @ApiOperation("设备分组分页列表")
    @PreAuthorize("@ss.hasPermi('point:deviceGroup:list')")
    @GetMapping("/list")
    public AjaxResult list(IbmsDeviceGroup ibmsDeviceGroup) {
//        startPage();
        List<IbmsDeviceGroup> list = ibmsDeviceGroupService.queryPageList(ibmsDeviceGroup);
        return AjaxResult.success(list);
    }

    /**
     * 导出设备分组列表
     */
    @ApiOperation("导出设备分组列表")
    @PreAuthorize("@ss.hasPermi('point:deviceGroup:export')")
    @Log(title = "设备分组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IbmsDeviceGroup ibmsDeviceGroup) {
        List<IbmsDeviceGroup> list = ibmsDeviceGroupService.queryPageList(ibmsDeviceGroup);
        ExcelUtil<IbmsDeviceGroup> util = new ExcelUtil<IbmsDeviceGroup>(IbmsDeviceGroup.class);
        util.exportExcel(response, list, "设备分组数据");
    }

    /**
     * 新增设备分组
     */
    @ApiOperation("新增设备分组")
    @PreAuthorize("@ss.hasPermi('point:deviceGroup:add')")
    @Log(title = "设备分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody IbmsDeviceGroup ibmsDeviceGroup) {
        return toAjax(ibmsDeviceGroupService.save(ibmsDeviceGroup));
    }

    /**
     * 修改设备分组
     */
    @ApiOperation("修改设备分组")
    @PreAuthorize("@ss.hasPermi('point:deviceGroup:edit')")
    @Log(title = "设备分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody IbmsDeviceGroup ibmsDeviceGroup) {
        return toAjax(ibmsDeviceGroupService.updateById(ibmsDeviceGroup));
    }

    /**
     * 删除设备分组
     */
    @ApiOperation("删除设备分组")
    @PreAuthorize("@ss.hasPermi('point:deviceGroup:remove')")
    @Log(title = "设备分组", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ibmsDeviceGroupService.removeBatchByIds(Arrays.asList(ids)));
    }

    /**
     * 获取设备分组详细信息
     */
    @ApiOperation("获取设备分组详细信息")
    @PreAuthorize("@ss.hasPermi('point:deviceGroup:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {

        return success(ibmsDeviceGroupService.getById(id));
    }


}
